"""
Case Type   : Compatibility
Case Name   : 验证时间日期处理函数的bool值输出
Create At   : 2024/10/21
Owner       : liu-tong-8848
Description :
              1.isfinite函数
Expect      :
              1.成功
History     :
"""

import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node


class SQL(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.Constant = Constant()
        self.primary_sh = CommonSH('PrimaryDbBmode')
        self.db_user_node = Node(node='PrimaryDbBmode')

    def test_add_dimension(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        step1 = '--step1：isfinite函数 expect：执行成功'
        self.log.info(step1)
        sql = "--isfinite(date) select isfinite(date '2021-01-12') as c; select isfinite('18:52:31') as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertNotIn("ERROR", result, "执行失败" + step1)
        sql = "select isfinite(date '2021-01-12') as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)
        sql = "select isfinite('18:52:31') as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)
        sql = "--isfinite(timestamp) select isfinite(timestamp '2021-01-12 23:59:59') as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertNotIn("ERROR", result, "执行失败" + step1)
        sql = "select isfinite(timestamp '9999-12-31 23:59:59') as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)
        sql = "--isfinite(interval) select isfinite(interval '4 hours') as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertNotIn("ERROR", result, "执行失败" + step1)
        sql = "select isfinite(interval '25 hours') as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)


    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
